package com.aaa.controller;

import com.aaa.entity.*;
import com.aaa.service.impl.Video_TypeServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: Video_TypeController
 * @Description: TODO
 * @Author: 86139
 * @Date: 2021/9/12 22:02
 * @Version:1.0
 **/
@RestController
@RequestMapping("video_type")
public class Video_TypeController {
    @Resource
    Video_TypeServiceImpl video_typeService;
    @RequestMapping("finAll")
    public PageInfo finAll(Integer pageNum, Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Video_Type> list = video_typeService.list();
        System.out.println("--------------------------------"+list);
        PageInfo<Video_Type> rolePageInfo = new PageInfo<Video_Type>(list);
        System.out.println(rolePageInfo);
        return rolePageInfo;
    }
    @RequestMapping("state")
    public boolean state(Video_Type videoType){
        return video_typeService.updateById(videoType);
    }
    @RequestMapping("add")
    public boolean add(Video_Type videoType){
        QueryWrapper<Video_Type> objectQueryWrapper = new QueryWrapper<>();
        objectQueryWrapper.eq("t_name",videoType.getTname());
        List<Map<String, Object>> list = video_typeService.listMaps(objectQueryWrapper);
        if(list.size()>0){
            return false;
        }
        videoType.setState("0");
        return video_typeService.save(videoType);
    }
    @RequestMapping("update")
    public boolean update(Video_Type videoType){
        List<Map<String,Object>> list = video_typeService.addAfter(videoType.getTid());
        if(list.size()>0){
            QueryWrapper<Video_Type> wrapper = new QueryWrapper<>();
            wrapper.eq("tid",videoType.getTid());
            Map<String,Object> list1 = video_typeService.listMaps(wrapper).get(0);
            if(list1.get("t_name").equals(videoType.getTname())){
                return video_typeService.updateById(videoType);
            }
            return false;
        }else {
            return video_typeService.updateById(videoType);
        }
    }
}
